#include <stdio.h>
#include <stdlib.h>

/*
 *行列交换
 * */
#define M 2
#define N 3
static void test1(void)
{
	int a[M][N] = {1,2,3,4,5,6},b[N][M];
	int i,j;

	for(i = 0;i<M;i++)
	{
		for (j = 0;j<N;j++)
		{
			printf("%d",a[i][j]);
			b[j][i] = a[i][j];

		}
		printf("\n");

	}
	printf("=======\n");
	for (i = 0;i<N;i++)
	{
		for (j = 0;j<M;j++)
		{
			printf("%d",b[i][j]);


		}

		printf("\n");
	}	

}


/*
 *求最大值及下标
 * */
static void test2(void)
{
	int arr[M][N]={43,4,13,89,9,7}; 
	int i,j;
	
	int row = 0,colum = 0,max = arr[0][0];
	
	for (i=0;i<M;i++)
	{
		
		for (j=0;j<N;j++)
		{
			
			if(arr[i][j] > max)
			{
				max = arr[i][j];
				row = i;
				colum = j;
			} 
		}
	}
	printf("row:%d,colum:%d max:%d\n",row,colum,max);

}
/*
 *求各行与各列的和
 * */
static void test3(void)
{
	int arr[M][N] = {43,4,13,89,9,7};
	int row_sum[M]={0};
	int colum_sum[N] = {0};
	
	int i,j;
	for(i=0;i<M;i++)
	{
		for(j=0;j<N;j++)
		{
			row_sum[i] +=arr[i][j];	
			colum_sum[j] += arr[i][j];
		}
		

	}

	for (i=0;i<M;i++)
	{
		printf(" %d\n",row_sum[i]);
	}
	printf("===========\n");
	for (j=0;j<N;j++)
	{
		printf(" %d\n ",colum_sum[j]);

	}

}
/*
 * 矩阵乘积
 * */
#define K 2
static void test4(void)
{
	int a[M][N] = {1,2,3,4,5,6};
	int b[N][K] = {1,0,0,1,1,0};
	int c[M][K] = {0};
	int i,j,k;
	for(i=0;i<M;i++)
	{
		for(j=0;j<K;j++)
		{
			for(k=0;k<N;k++)
			{
				c[i][j]+= a[i][k] *b[k][j];

			}

		}

	}

	for(i=0;i<M;i++)
	{
		for(j=0;j<K;j++)
		{
			printf("%d  ",c[i][j]);


		}
		printf("\n");

	}



}
int main(void)
{
//	test1();
//	test2();
//	test3();
	test4();
	exit(0);
}
